-
-
Notifications
You must be signed in to change notification settings - Fork 671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: ImageRegion
support C++17 structured binding
#4367
ENH: ImageRegion
support C++17 structured binding
#4367
Conversation
0a73924
to
b2f8338
Compare
@dzenanz Thanks for you approval! I think it would be pretty cool if Unfortunately the code currently appears to trigger some undeserved clang-tidy warnings, saying modification of 'std' namespace can result in undefined behavior [cert-dcl58-cpp], as I mentioned at llvm/llvm-project#45454 (comment) Even though the code appears correct, as confirmed by @Febbe at llvm/llvm-project#45454 (comment) Shall I locally disable this specific Clang-Tidy warning, by adding something like |
Suppressing the warning sounds better to me. |
e464883
to
bf37e85
Compare
bf37e85
to
2e98742
Compare
ImageRegion
support C++17 structured binding
2e98742
to
5cf540e
Compare
Added `get()` member functions and specializations of `std::tuple_size` and `std::tuple_element` for ImageRegion, in order to support structured binding, for example: auto [index, size] = image.GetRequestedRegion(); Suppressed the undeserved Clang-Tidy "cert-dcl58-cpp" warnings that appeared when specializing those `std` templates.
5cf540e
to
c8c9983
Compare
@thewtex Although this is a rather small PR, I think it has a certain "cool factor", allowing users to do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@N-Dekker very, very cool! 😎
Yes, I am making a mental note for the 5.4rc3 release notes.
72aa9a6
into
InsightSoftwareConsortium:master
Replaced initializations of the form: SizeType size = region.GetSize(); IndexType index = region.GetIndex(); By using structured binding of the form `auto [index, size] = region`, as was introduced by pull request InsightSoftwareConsortium#4367 commit 72aa9a6 "ENH: `ImageRegion` support C++17 structured binding" Did so by Notepad++ Replace in Files, using regular expressions: Find what: ^([ ]+)const (.*)\w.+[ ]+(\w+) = (.+)\.GetIndex\(\);\r\n\1const \2\w+[ ]+(\w+) = \4\.GetSize\(\);$ Replace with: $1const auto [$3, $5] = $4; Find what: ^([ ]+)const (.*)\w.+[ ]+(\w+) = (.+)\.GetSize\(\);\r\n\1const \2\w+[ ]+(\w+) = \4\.GetIndex\(\);$ Replace with: $1const auto [$5, $3] = $4; Find what: ^([ ]+)(.*)\w.+[ ]+(\w+) = (.+)\.GetIndex\(\);\r\n\1\2\w+[ ]+(\w+) = \4\.GetSize\(\);$ Replace with: $1auto [$3, $5] = $4; Find what: ^([ ]+)(.*)\w.+[ ]+(\w+) = (.+)\.GetSize\(\);\r\n\1\2\w+[ ]+(\w+) = \4\.GetIndex\(\);$ Replace with: $1auto [$5, $3] = $4;
Replaced initializations of the form: SizeType size = region.GetSize(); IndexType index = region.GetIndex(); By using structured binding of the form `auto [index, size] = region`, as was introduced by pull request InsightSoftwareConsortium#4367 commit 72aa9a6 "ENH: `ImageRegion` support C++17 structured binding" Did so by Notepad++ Replace in Files, using regular expressions: Find what: ^([ ]+)const (.*)\w.+[ ]+(\w+) = (.+)\.GetIndex\(\);\r\n\1const \2\w+[ ]+(\w+) = \4\.GetSize\(\);$ Replace with: $1const auto [$3, $5] = $4; Find what: ^([ ]+)const (.*)\w.+[ ]+(\w+) = (.+)\.GetSize\(\);\r\n\1const \2\w+[ ]+(\w+) = \4\.GetIndex\(\);$ Replace with: $1const auto [$5, $3] = $4; Find what: ^([ ]+)(.*)\w.+[ ]+(\w+) = (.+)\.GetIndex\(\);\r\n\1\2\w+[ ]+(\w+) = \4\.GetSize\(\);$ Replace with: $1auto [$3, $5] = $4; Find what: ^([ ]+)(.*)\w.+[ ]+(\w+) = (.+)\.GetSize\(\);\r\n\1\2\w+[ ]+(\w+) = \4\.GetIndex\(\);$ Replace with: $1auto [$5, $3] = $4; Manually added `const` to bindings in `SetBound(const SizeType &)` member functions, and excluded `ImageIORegion`.
Replaced initializations of the form: SizeType size = region.GetSize(); IndexType index = region.GetIndex(); By using structured binding of the form `auto [index, size] = region`, as was introduced by pull request InsightSoftwareConsortium#4367 commit 72aa9a6 "ENH: `ImageRegion` support C++17 structured binding" Did so by Notepad++ Replace in Files, using regular expressions: Find what: ^([ ]+)const (.*)\w.+[ ]+(\w+) = (.+)\.GetIndex\(\);\r\n\1const \2\w+[ ]+(\w+) = \4\.GetSize\(\);$ Replace with: $1const auto [$3, $5] = $4; Find what: ^([ ]+)const (.*)\w.+[ ]+(\w+) = (.+)\.GetSize\(\);\r\n\1const \2\w+[ ]+(\w+) = \4\.GetIndex\(\);$ Replace with: $1const auto [$5, $3] = $4; Find what: ^([ ]+)(.*)\w.+[ ]+(\w+) = (.+)\.GetIndex\(\);\r\n\1\2\w+[ ]+(\w+) = \4\.GetSize\(\);$ Replace with: $1auto [$3, $5] = $4; Find what: ^([ ]+)(.*)\w.+[ ]+(\w+) = (.+)\.GetSize\(\);\r\n\1\2\w+[ ]+(\w+) = \4\.GetIndex\(\);$ Replace with: $1auto [$5, $3] = $4; Manually added `const` to bindings in `SetBound(const SizeType &)` member functions, excluded `ImageIORegion`, and removed `Index` and `Size` type aliases that are no longer used after this commit.
Did this PR cause these compile errors: |
static_asserts are from #4373. BTW users add rather often |
Replaced initializations of the form: SizeType size = region.GetSize(); IndexType index = region.GetIndex(); By using structured binding of the form `auto [index, size] = region`, as was introduced by pull request InsightSoftwareConsortium#4367 commit 72aa9a6 "ENH: `ImageRegion` support C++17 structured binding" Did so by Notepad++ Replace in Files, using regular expressions: Find what: ^([ ]+)const (.*)\w.+[ ]+(\w+) = (.+)\.GetIndex\(\);\r\n\1const \2\w+[ ]+(\w+) = \4\.GetSize\(\);$ Replace with: $1const auto [$3, $5] = $4; Find what: ^([ ]+)const (.*)\w.+[ ]+(\w+) = (.+)\.GetSize\(\);\r\n\1const \2\w+[ ]+(\w+) = \4\.GetIndex\(\);$ Replace with: $1const auto [$5, $3] = $4; Find what: ^([ ]+)(.*)\w.+[ ]+(\w+) = (.+)\.GetIndex\(\);\r\n\1\2\w+[ ]+(\w+) = \4\.GetSize\(\);$ Replace with: $1auto [$3, $5] = $4; Find what: ^([ ]+)(.*)\w.+[ ]+(\w+) = (.+)\.GetSize\(\);\r\n\1\2\w+[ ]+(\w+) = \4\.GetIndex\(\);$ Replace with: $1auto [$5, $3] = $4; Manually added `const` to bindings in `SetBound(const SizeType &)` member functions, excluded `ImageIORegion`, and removed `Index` and `Size` type aliases that are no longer used after this commit.
After pull request InsightSoftwareConsortium#4367 commit 72aa9a6 (ENH: `ImageRegion` support C++17 structured binding), a few unimportant `-Wmismatched-tags` warnings appeared from Mac10.13-AppleClang-rel-x86_64, at https://open.cdash.org/build/9256915 This commit locally disables those warnings, followed: https://github.com/Naios/continuable/blob/121265df7123cf672ea8db917eaca2d0fbd9aef5/include/continuable/continuable-result.hpp#L291-L308 Reported to me by mail, from Dženan Zukić and Sean McBride.
After pull request InsightSoftwareConsortium#4367 commit 72aa9a6 (ENH: `ImageRegion` support C++17 structured binding), a few unimportant `-Wmismatched-tags` warnings appeared from Mac10.13-AppleClang-rel-x86_64, at https://open.cdash.org/build/9256915 This commit locally disables those warnings, followed: https://github.com/Naios/continuable/blob/121265df7123cf672ea8db917eaca2d0fbd9aef5/include/continuable/continuable-result.hpp#L291-L308 Reported to me by mail, from Dženan Zukić and Sean McBride.
After pull request InsightSoftwareConsortium#4367 commit 72aa9a6 (ENH: `ImageRegion` support C++17 structured binding), a few unimportant `-Wmismatched-tags` warnings appeared from Mac10.13-AppleClang-rel-x86_64, at https://open.cdash.org/build/9256915 This commit locally disables those warnings, followed: https://github.com/Naios/continuable/blob/121265df7123cf672ea8db917eaca2d0fbd9aef5/include/continuable/continuable-result.hpp#L291-L308 Reported to me by mail, from Dženan Zukić and Sean McBride.
After pull request InsightSoftwareConsortium#4367 commit 72aa9a6 (ENH: `ImageRegion` support C++17 structured binding), a few unimportant `-Wmismatched-tags` warnings appeared from Mac10.13-AppleClang-rel-x86_64, at https://open.cdash.org/build/9256915 as was reported to me by mail, from Dženan Zukić and Sean McBride. This commit locally disables those warnings, following https://github.com/Naios/continuable/blob/121265df7123cf672ea8db917eaca2d0fbd9aef5/include/continuable/continuable-result.hpp#L291-L308 by Denis Blank.
After pull request #4367 commit 72aa9a6 (ENH: `ImageRegion` support C++17 structured binding), a few unimportant `-Wmismatched-tags` warnings appeared from Mac10.13-AppleClang-rel-x86_64, at https://open.cdash.org/build/9256915 as was reported to me by mail, from Dženan Zukić and Sean McBride. This commit locally disables those warnings, following https://github.com/Naios/continuable/blob/121265df7123cf672ea8db917eaca2d0fbd9aef5/include/continuable/continuable-result.hpp#L291-L308 by Denis Blank.
Added
get()
member functions and specializations ofstd::tuple_size
andstd::tuple_element
for ImageRegion, in order to support structured binding, for example: